package com.example.flow.dao.impl;


import com.example.flow.dao.FlowProcessExtDao;
import com.example.flow.dao.mapper.FlowProcessExtMapper;
import com.example.flow.dao.model.FlowProcessExt;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;

@Repository
public class RdsFlowProcessExtDao implements FlowProcessExtDao {

    private final FlowProcessExtMapper flowProcessExtMapper;

    public RdsFlowProcessExtDao(FlowProcessExtMapper flowProcessExtMapper) {
        this.flowProcessExtMapper = flowProcessExtMapper;
    }

    @Override
    public FlowProcessExt findByProcessId(String processId) {
        if (StringUtils.isBlank(processId)) {
            return null;
        }
        FlowProcessExt processExt = new FlowProcessExt();
        processExt.setProcessId(processId);
        return flowProcessExtMapper.selectOne(processExt);
    }

    @Override
    public void upgradeByProcessId(String processId, FlowProcessExt ext) {
        if (StringUtils.isBlank(processId)) {
            return;
        }
        FlowProcessExt update = new FlowProcessExt();
        update.setProcessId(processId);
        flowProcessExtMapper.updateByRecordSelective(ext, update);
    }

    @Override
    public void deleteByProcessId(String processId) {
        if (StringUtils.isBlank(processId)) {
            return;
        }
        FlowProcessExt processExt = new FlowProcessExt();
        processExt.setProcessId(processId);
        flowProcessExtMapper.delete(processExt);
    }

    @Override
    public void insert(FlowProcessExt ext) {
        flowProcessExtMapper.insert(ext);
    }
}